import 'package:flutter/material.dart';

import '../../../generated/l10n.dart';
import 'package:lib_music/lib_music.dart';
import 'package:lib_music/lib_mic.dart';

import '../base/BaseWidget.dart';
import '../base/MyGestureDetector.dart';
import '../base/TitleBarWidget.dart';

class MicPage extends StatefulWidget {
  const MicPage({super.key});

  @override
  State<MicPage> createState() => _MicPageState();
}

class _MicPageState extends State<MicPage> {
  bool isMicStart = false;

  @override
  void dispose() {
    LibMic.instance.stopRecord();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BaseWidget(
        child: Column(
      children: [
        TitleBarWidget(title: S.of(context).str_id_26),

        Expanded(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            MyGestureDetector(
              onTap: () async {
                if (isMicStart) {
                  LibMic.instance.stopRecord();
                } else {
                  LibMic.instance.startRecord();
                }
                setState(() {
                  isMicStart = !isMicStart;
                });
              },
              child: Container(
                width: 94,
                height: 94,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(100),
                    gradient: isMicStart
                        ? const LinearGradient(
                            begin: Alignment.topCenter,
                            end: Alignment.bottomCenter,
                            colors: [Color(0xff313744), Color(0xff313744)],
                          )
                        : const LinearGradient(
                            begin: Alignment.topCenter,
                            end: Alignment.bottomCenter,
                            colors: [Color(0xff41EAFA), Color(0xff4A79FF)],
                          )),
                child: Center(
                  child: Text(
                    isMicStart ? S.of(context).str_id_28 : S.of(context).str_id_27,
                    style: const TextStyle(color: Colors.white, fontSize: 18),
                  ),
                ),
              ),
            ),
          ],
        ))
      ],
    ));
  }
}
